// 抽象饮品类
abstract class Beverage {
    public abstract String getDescription();
    public abstract double cost();
}

// 具体饮品类 - 咖啡
class Coffee extends Beverage {
    @Override
    public String getDescription() {
        return "咖啡";
    }

    @Override
    public double cost() {
        return 10.0;  // 假设咖啡价格为10元
    }
}

// 抽象装饰者类（配料装饰者）
abstract class CondimentDecorator extends Beverage {
    protected Beverage beverage;
}

// 具体装饰者类 - 牛奶配料
class Milk extends CondimentDecorator {
    public Milk(Beverage beverage) {
        this.beverage = beverage;
    }

    @Override
    public String getDescription() {
        return beverage.getDescription() + ", 加了牛奶";
    }

    @Override
    public double cost() {
        return beverage.cost() + 2.0;  // 加牛奶增加2元成本
    }
}

// 具体装饰者类 - 糖配料
class Sugar extends CondimentDecorator {
    public Sugar(Beverage beverage) {
        this.beverage = beverage;
    }

    @Override
    public String getDescription() {
        return beverage.getDescription() + ", 加了糖";
    }

    @Override
    public double cost() {
        return beverage.cost() + 1.0;  // 加糖增加1元成本
    }
}

// 测试装饰者模式
public class DecoratorTest {
    public static void main(String[] args) {
        Beverage coffee = new Coffee();
        Beverage coffeeWithMilk = new Milk(coffee);
        Beverage coffeeWithMilkAndSugar = new Sugar(coffeeWithMilk);

        System.out.println(coffeeWithMilkAndSugar.getDescription());
        System.out.println("价格: " + coffeeWithMilkAndSugar.cost() + " 元");
    }
}